import { defineStore } from 'pinia'
import { ref } from 'vue'
import { loginService } from '@/apis/login'

export const loginStore = defineStore('loginStore', () => {
    const token = ref('')
    const id = ref('')
    const name = ref('')
    const avatar = ref('')

    const setToken = async (form) => {
        const res = await loginService(form)
        token.value = res.data.data.token
        name.value = res.data.data.name
        id.value = res.data.data.id
        avatar.value = res.data.data.avatar
    }

    return {
        token,
        name,
        id,
        avatar,
        setToken
    }
}, {
    persist: true
})
